#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 1e5 + 10;
int n, a[N];
/*
1 1 2 2 3
1 2 3 4 
136 136 136 136 136 136 136 136 2417 2417

*/
signed main(){
    freopen("duel.in", "r", stdin);
    freopen("duel.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    sort(a + 1, a + 1 + n);
    int p = 1, cnt = 0;
    for(int i = 1; i <= n; i++){
        cnt++;
        if(a[i] != a[i + 1]){
            p = max(p, i + 1);
            //cout << n - p + 1 << "s";
            if(n - p + 1 > cnt){
                p += cnt - 1;
            }else{
                cout << n - i + cnt - (n - p + 1) << endl;
                return 0;
            }
            cnt = 0;
        }
    }
    for(int i = n; i >= 1; i--){
        if(a[i] != a[n]){
            cout << n - i << endl;
            return 0;
        }
    }
}
